//
//  HACLayoutCell.m
//  HACDispatcher
//
//  Created by Chengjie on 2019/5/15.
//  Copyright © 2019 Happy. All rights reserved.
//

#import "HACLayoutCell.h"
#import <Masonry/Masonry.h>

@implementation HACLayoutCellModel

- (CGFloat)cellHeight {
    return UITableViewAutomaticDimension;
}

- (NSString *)reusableIdentifier {
    return NSStringFromClass([HACLayoutCell class]);
}

@end




@interface HACLayoutCell ()
@property (nonatomic, strong) UILabel *studentNameLable;
@property (nonatomic, strong) UIView *bottomLineView;
@property (nonatomic, strong) UIView *customView;
@end

@implementation HACLayoutCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.contentView.backgroundColor = [UIColor colorWithRed:0.1 green:0.8 blue:0.1 alpha:1];
        
        [self.contentView addSubview:self.studentNameLable];
        [self.contentView addSubview:self.customView];
        [self.contentView addSubview:self.bottomLineView];
        
        [self.studentNameLable mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.contentView.mas_top).offset(12);
            make.left.equalTo(self.contentView.mas_left).offset(15);
            make.right.equalTo(self.contentView.mas_right).offset(-15);
        }];
        
        [self.customView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.studentNameLable.mas_bottom);
            make.left.equalTo(self.contentView.mas_left);
            make.right.equalTo(self.contentView.mas_right);
            make.height.equalTo(@(15));
            make.bottom.equalTo(self.contentView.mas_bottom).offset(-1);
        }];
        [self.bottomLineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self.contentView.mas_bottom);
            make.left.equalTo(self.contentView.mas_left);
            make.right.equalTo(self.contentView.mas_right);
            make.height.equalTo(@(1));
        }];
    }
    return self;
}

- (void)configCellModel:(HACLayoutCellModel *)cellModel {
    self.studentNameLable.text = cellModel.studentName;
}

- (UILabel *)studentNameLable {
    if (!_studentNameLable) {
        _studentNameLable = [UILabel new];
        _studentNameLable.numberOfLines = 0;
        _studentNameLable.textColor = [UIColor whiteColor];
        _studentNameLable.font = [UIFont systemFontOfSize:22];
    }
    return _studentNameLable;
}

- (UIView *)bottomLineView {
    if (!_bottomLineView) {
        _bottomLineView = [UIView new];
        _bottomLineView.backgroundColor = [UIColor redColor];
    }
    return _bottomLineView;
}

- (UIView *)customView {
    if (!_customView) {
        _customView = [UIView new];
        _customView.backgroundColor = [UIColor yellowColor];
    }
    return _customView;
}

@end
